package ligne2vie.topos.client.panels;

import com.google.gwt.user.client.ui.DecoratedTabPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * The class {@link ControlPanel} models the {@link Widget} to display on the left part of the application, allowing
 * controlling the whole application.
 * <p>
 * It is designed as a several-tabs widget, each containing a dedicated widget (search, participate, ...).
 * 
 * @author thuguerre
 * @since 1.0.0
 */
public class ControlPanel extends DecoratedTabPanel {

	private SearchPanel searchPanel;
	private ParticipationPanel participationPanel;
	private AboutPanel aboutWidget;

	/**
	 * {@link ControlPanel}'s singleton instance.
	 */
	private static ControlPanel instance = null;

	/**
	 * Default constructor. Initialize all inner widgets.
	 */
	private ControlPanel() {

		super();

		// --- instantiating panels
		searchPanel = new SearchPanel();
		participationPanel = new ParticipationPanel();
		aboutWidget = new AboutPanel();

		// --- adding instantiated panels
		super.add(searchPanel, "Chercher");
		super.add(participationPanel, "Participer");
		super.add(aboutWidget, "A propos");

		// --- default configuration
		this.setAnimationEnabled(true);
		this.selectTab(0);
	}

	/**
	 * If the user is not correctly logged in, he should do to participate. This method displays the message asking him
	 * to log in using the link above the control panel. The panel containing the links is not displayed and no action
	 * is possible.
	 */
	protected void displayLogInPanel() {

		// --- removing participation tab

		super.remove(1);

		// --- creating message asking user to log in

		VerticalPanel messagePanel = new VerticalPanel();
		messagePanel.add(new HTML("Afin de participer gratuitement en fournissant vos propres informations,"
				+ " vous devez vous connecter &agrave; l'aide d'un compte Google, en cliquant sur le lien ci-dessus."));

		// --- inserting message to display into control panel

		super.insert(messagePanel, "Participer", 1);
	}

	/**
	 * @return {@link ControlPanel}'s singleton instance.
	 */
	public static ControlPanel getInstance() {

		if (instance == null) {
			instance = new ControlPanel();
		}

		return instance;
	}
}
